package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.InventoryCheck;
import com.ruoyi.system.service.IInventoryCheckService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 盘点单Controller
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/inventoryCheck")
public class InventoryCheckController extends BaseController
{
    @Autowired
    private IInventoryCheckService inventoryCheckService;

    /**
     * 查询盘点单列表
     */
    @RequiresPermissions("system:inventoryCheck:list")
    @GetMapping("/list")
    public TableDataInfo list(InventoryCheck inventoryCheck)
    {
        startPage();
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(inventoryCheck);
        return getDataTable(list);
    }

    /**
     * 导出盘点单列表
     */
    @RequiresPermissions("system:inventoryCheck:export")
    @Log(title = "盘点单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InventoryCheck inventoryCheck)
    {
        List<InventoryCheck> list = inventoryCheckService.selectInventoryCheckList(inventoryCheck);
        ExcelUtil<InventoryCheck> util = new ExcelUtil<InventoryCheck>(InventoryCheck.class);
        util.exportExcel(response, list, "盘点单数据");
    }

    /**
     * 获取盘点单详细信息
     */
    @RequiresPermissions("system:inventoryCheck:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryCheckService.selectInventoryCheckById(id));
    }

    /**
     * 新增盘点单
     */
    @RequiresPermissions("system:inventoryCheck:add")
    @Log(title = "盘点单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.insertInventoryCheck(inventoryCheck));
    }

    /**
     * 修改盘点单
     */
    @RequiresPermissions("system:inventoryCheck:edit")
    @Log(title = "盘点单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryCheck inventoryCheck)
    {
        return toAjax(inventoryCheckService.updateInventoryCheck(inventoryCheck));
    }

    /**
     * 删除盘点单
     */
    @RequiresPermissions("system:inventoryCheck:remove")
    @Log(title = "盘点单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryCheckService.deleteInventoryCheckByIds(ids));
    }
}
